import { _decorator } from 'cc';
import AudioSetting from 'db://cocos-ext/base/AudioSetting';
import AudioComponent from 'db://cocos-ext/component/AudioComponent';
import { games, yy } from 'yycore';

const { ccclass, property } = _decorator;


/**
 * 音效控制器; 【继承于AudioComponent，增加了一个YY事件同步】
 * 采用监听事件机制--EVENT_KEY_PLAY_AUDIO
 * 支持挂载多个音效控制组件
 */
@ccclass("AudioComp")
export default class AudioComp extends AudioComponent {

    onLoad() {
        super.onLoad();
        yy.event.on(this, games.events.SettingChanged, (e: games.events.SettingChanged) => {
            switch (e.settingType) {
                case 1:
                    AudioSetting.mute = games.setting.isMute;
                    break;
                case 2:
                    AudioSetting.BGM = games.setting.isMusicEnable;
                    break;
                case 3:
                    AudioSetting.sound = games.setting.isEffectEnable;
                    break;
                case 4:
                    AudioSetting.voice = games.setting.isVoiceEnable;
                    break;
            }
            if (e.settingType == 1 || e.settingType == 2)
                this.checkAndUpdateBGM();
        });
    }

}
